<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            height: 2200px;
        }

        #returnTop {
            width: 50px;
            height: 50px;
            background: url(images/返回顶部\ \ \(2\).png);
            border: 1px solid #ccc;
            position: fixed;
            top: 500px;
            right: 40px;
            display: none;
        }
    </style>
</head>

<body>
    <div id="returnTop"></div>
    <script>
        var returnTop = document.querySelector("#returnTop");
        document.addEventListener('scroll', function () {
            let sTop = document.documentElement.scrollTop || document.body.scrollTop;
            if (sTop > 300) {
                returnTop.style.display = 'block';
            }
            else {
                returnTop.style.display = 'none';
            }

        })
    </script>
</body>

</html>